<link href="css/style.css" rel="stylesheet" type="text/css" />

<?php 
	include 'operations/connection.php';
	$query1 = mysql_query("SELECT e.FullName,dl.DepartmentName 
							FROM employee e, department_lang dl 
							WHERE dl.IDDepartment=e.IDDepartment AND dl.LangID='$lang' AND e.IDEmployee='$id_employee';");
	while ($row = mysql_fetch_array($query1))
		{
			$FullName = $row[FullName];
			$DepartmentName = $row[DepartmentName];
		}
	
if($_REQUEST['action']){
	$action=$_REQUEST['action'];
	$id=$_REQUEST['idapprovedoc'];
	if($_REQUEST['action']=="editform" || $_REQUEST['action']=="my_declined" || $_REQUEST['action']=="my_sending"){
		$sql="select Tile,Content,Content2,Timecreate,TripDate,Description from approvedoc where IDApproveDoc='".$id."'";
		$mangnoidung= mysql_fetch_assoc(mysql_query($sql));
		$fcreate_date = convert_datetime($mangnoidung[Timecreate]);
		$ftrip_date = convert_datetime($mangnoidung[TripDate]);
		$ftitle=$mangnoidung[Tile];
		$fdescription=$mangnoidung[Description];
		$fn222=$mangnoidung[Content];
		$fn223=$mangnoidung[Content2];
	}else if($_REQUEST['action']=="newform"){
		$fcreate_date = time();
		$ftrip_date = time()+( 1 - date('w'))*24*3600;
		$ftitle="";
		$fdescription="";
		$fn222="";
		$fn223="";
	}
}
//datetime (YYYY-MM-DD HH:MM:SS)
function convert_datetime($str) {
	list($date, $time) = explode(' ', $str);
	list($year, $month, $day) = explode('-', $date);
	if (isset($time)) {
		list($hour, $minute, $second) = explode(':', $time);
	}
	$timestamp = mktime($hour, $minute, $second, $month, $day, $year);
	
	return $timestamp;
}


?>
<script  LANGUAGE="JavaScript" type="text/javascript">
function ch(){
	if(document.f.title.value==""){
		alert('<?=$l_titlemusthavedate?>');
		document.f.title.focus();
		return false;
	}
}
function focusOnMyInputBox(e,ten){
    var x;
    if(window.event) // IE8 and earlier
    	{
    	x=e.keyCode;
    	}
    else if(e.which) // IE9/Firefox/Chrome/Opera/Safari
    	{
    	x=e.which;
    	}
	if(x==13){
		document.getElementById(ten).focus();
		return false;
	}else{
		return true;
	}
}
</script>

<div class="nav_top">
       		<div class="nav_tit"><?php echo $l_weekly_report?></div>     
            <div class="rehome"><a href="mainPhone.php"><?php echo $l_menu?></a></div>       
       	</div>
	<form method="post" action="newform-handle.php" onsubmit="return ch()" name="f">
		<input type="hidden" name='type' value="<?=$type?>" />
		<input type="hidden" name='action' value="<?=$action?>" />
		<input type="hidden" name='id' value="<?=$id?>" />
		<input type="hidden" name='thisweek' value="<?=$ftrip_date?>" />
        <div class="main_content"  style="min-height: 895px">
            <ul class="top_but">
				<li>
				<?php if($action=="my_declined" || $action=="my_sending"){?>
					<a href="mydocument-list-mydocument-saved-content"><img src="images/back.png" alt="" /> </a>
				<?php }else{?>
					
				<?php if(isset($_REQUEST['page'])){?>
					<a href="<?=$_SERVER['HTTP_REFERER']?>&page=<?=$_REQUEST['page']?>"><img src="images/back.png" alt="" /> </a>
				<?php }else{?>
					<a href="<?=$_SERVER['HTTP_REFERER']?>"><img src="images/back.png" alt="" /> </a>
				<?php } 
				} ?>
				
				
					<p class="hidden" >
					<?=$l_back?>
					</p>
				</li>
				<li><input type="submit" name="Save" value="" style="background:url(images/save.png) no-repeat; width:36px; height:36px; border:none; position:absolute; top:0px; left:0px; right:0px; bottom:0px; margin:auto" /><p class="hidden"><?=$l_save?></p></li>
				<li><input type="submit" name="Send" value="" style="background:url(images/send.png) no-repeat; width:36px; height:36px; border:none; position:absolute; top:0px; left:0px; right:0px; bottom:0px; margin:auto" /><p class="hidden" ><?=$l_send?></p></li>
			<?php 
			
				if($_REQUEST['action']){
					if($_REQUEST['action']=="editform" || $_REQUEST['action']=="my_declined"){
						?>
						
						<li><input type="submit" name="Delete" value=""
						style="background: url(images/deny.png) no-repeat; width: 36px; height: 36px; border: none; position: absolute; top: 0; left: 0; right: 0; bottom: 0; margin: auto" />
						<p class="hidden">
						<?=$l_delete?>
						</p></li>
						
						<?php 
					}
				}
			
			
			?>
			
			</ul>
            <table class="tcontent" cellpadding="5" cellspacing="0">               
                <tr>
                	<td width="15%" class="col_left"><?=$l_title?></td>
                    <td><input type="text" id='title' name='title' onkeypress ="return focusOnMyInputBox(event,'description');"  style="height:24px; width:100%; border:1px solid #c4c0c9;line-height: 24px;" value="<?=$ftitle ?>"/></td>
                </tr>
                <tr>
                	<td class="col_left"><?=$l_description?></td>
                    <td><textarea rows="3" id="description" name="description" cols="5" style="width:100%; border:1px solid #c4c0c9" ><?=$fdescription ?></textarea></td>
                </tr>                                      
            </table>
            <br />
            <table class="tcontent" cellpadding="5" cellspacing="0">               
                <tr>
                	<td style="text-align:left"><b><?=$l_writer?></b> <?=$FullName?></td>
                    <td style="text-align:left"><b><?=$l_department?></b> <?=$DepartmentName?></td>
                </tr>
                <tr>
                	<td style="text-align:left"><b><?php echo $l_Resultofthisweek;?></b><?php echo ' ('.date('Y.m.d',$ftrip_date).' - '.date('Y.m.d',$ftrip_date+ (7*24*3600)).')';?></td>
                    <td style="text-align:left"><b><?php echo $l_Planofnextweek;?></b><?php echo ' ('.date('Y.m.d',$ftrip_date+ (7*24*3600)).' - '.date('Y.m.d',$ftrip_date+ (14*24*3600)).')';?></td>
                </tr>         
                <tr>
                	<td style="text-align:left">
                	<textarea rows="" cols="" id="n222" class="n222"	name="n222"  style="width: 100%"><?php echo $fn222;?></textarea>
                	<div align="left">
					<a  onkeydown="return CKEDITOR.tools.callFunction(0, 12, event);"
						 id="cke_22" class="cke_off cke_button_image"
						   title=Image role=button tabIndex=-1 aria-labelledby=cke_22_label
						   onclick="CKEDITOR.tools.callFunction(17, this); return false;" href="javascript:void('Image')" ? unselectable="on" 
						   >
							  <input class="buttonProject" type="button" style="margin: 5px 0;" value="Insert images" /> 
						  </a>
				</div>
					</td>
                    <td style="text-align:left">
                    <textarea rows="" cols="" id="n223" class="n222"	name="n223"  style="width: 100%"><?php echo $fn223;?></textarea>
                    <div align="left">
					<a  onkeydown="return CKEDITOR.tools.callFunction(1,47, event);"
						 id="cke_80" class="cke_off cke_button_image"
						   title=Image role=button tabIndex=-1 aria-labelledby=cke_21_label
						   onclick="CKEDITOR.tools.callFunction(65, this); return false;" href="javascript:void('Image')" ? unselectable="on" 
						   >
							  <input class="buttonProject" type="button" style="margin: 5px 0;" value="Insert images" /> 
				    </a>
				</div>
					</td>
                </tr>                                           
            </table>
      </div>
     </form>